﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ORM.Business.Interfaces;
using ORM.Business.Models;
using ORM.Business.Models.Entities;
using ORM.Framework.Filters;
using ORM.Resources;
using ORM.Web.Models;

namespace ORM.Areas.Admin.Controllers
{
    [PermissionAuthorize(Permissions = KeyObject.Permission.ManageContents)]
    public class ManageContentController : AdminControllerBase
    {
        private IQuestionRepository _iQuestionRepository;
        private IGuideRepository _iGuideRepository;
        public ManageContentController(IQuestionRepository iQuestionRepository, IGuideRepository iGuideRepository)
        {
            _iQuestionRepository = iQuestionRepository;
            _iGuideRepository = iGuideRepository;


        }
        #region Manage Questions

        public ActionResult ManageQuestions()
        {
            IList<Question> questionsList = new List<Question>();

            var feedback = _iQuestionRepository.GetAllQuestions();

            //Set default value for Total record
            ViewData["Total"] = 0;

            if (feedback.Success)
            {
                questionsList = feedback.Questions;
                //ViewData["Total"] = feedback.Total;
            }
            else
            {
                SetMessage(feedback.Message, MessageType.Error);
            }

            return View(questionsList);
        }

        public ActionResult DeleteQuestion(int id)
        {
            var feedback = _iQuestionRepository.DeleteQuestion(id);

            if (feedback.Success)
            {
                SetMessage(Messages.DeleteQuestionSuccess, MessageType.Success);
            }
            else
            {
                SetMessage(feedback.Message, MessageType.Error);
            }

            return RedirectToAction("ManageQuestions");
        }

        #endregion
        #region Manage Guides

        public ActionResult ManageGuides()
        {
            IList<Guide> guidesList = new List<Guide>();

            var feedback = _iGuideRepository.GetAllGuides();

            //Set default value for Total record
            ViewData["Total"] = 0;

            if (feedback.Success)
            {
                guidesList = feedback.Guides;
                //ViewData["Total"] = feedback.Total;
            }
            else
            {
                SetMessage(feedback.Message, MessageType.Error);
            }

            return View(guidesList);
        }

        public ActionResult DeleteGuide(int id)
        {
            var feedback = _iGuideRepository.DeleteGuide(id);

            if (feedback.Success)
            {
                SetMessage(Messages.DeleteGuideSuccess, MessageType.Success);
            }
            else
            {
                SetMessage(feedback.Message, MessageType.Error);
            }

            return RedirectToAction("ManageGuides");
        }

        #endregion

    }
}
